Handy functions exposes to rendering logic for formatting.
Properties
Name | Returns | Notes | Example |
---|---|---|---|
now | Date | Get the current date and time | |
yearStart | Date | Returns the date of the first day of the current year | |
currentDateService | CurrentDateService | ||
list | ResourceList | Just create a new list, same as newList() | |
port | int | Attempts to find the port of the current request, defaults to 80 | |
portString | String | Returns empty string if the current request is on port 80, otherwise returns the port number prefixed with a colon, eg :8080 | |
baseWebsiteUrl | String | ||
countryCodes | CountryCodes | ||
countryCodeOfOrg | CountryCode | ||
queryString | String | Returns the querystring of the current request. This is the question mark and everything following it | |
crypto | CryptoImpl | Get an instance of the CryptoImpl class | |
geoIPService | GeoIPService | Get an instance of the GeoIPService class | |
randomGuid | String | Calculate a random UUID |
Methods
Name | Returns | Notes | Example |
---|---|---|---|
toString ( o ) | String | Null safe method, returns empty string if the value is null | |
toBool ( o ) | Boolean | Convert just about anything truthy to a Boolean, or return null if its blank | |
toDecimal ( o, places ) | BigDecimal | Convert just about anything to a BigDecimal | |
toDouble ( o ) | Double | Convert just about anything to a Double precision number If null returns zero. | |
toInteger ( o ) | Integer | Attempt to convert to an Integer, where nulls are returned as zero | |
toLong ( o ) | Long | Attempt to convert anythiong to a Long number. Defaults to zero, so will never return null | |
toLong ( oVal, withNulls ) | Long | Attempt to convert to a Long number, optionally represent empty values either as null or zero | |
toPath ( s ) | Path | Convert the given string to a Path object, like /a/b/c | |
getFileName ( s ) | String | Get the last path segment (ie the file name) from a path string | |
getYear ( o ) | int | Convert the given object to a date and return the year portion | |
getMonth ( o ) | int | Convert to a date and return the month component, one indexed!! Also attempts a 3 letter starts with, so will return 1 for Jan, January, etc, and 12 for dec, DECEMBER, etc | |
getDayOfMonth ( o ) | int | Convert to a date and then return the day of the month (1 indexed) | |
getHour ( o ) | int | Convert to a date and return the hour component | |
getMinute ( o ) | int | Convert to a date and return the minute component | |
getDayOfWeek ( o ) | int | Returns the day of the week, 1 being Sunday and 7 being Saturday | |
getDayOfWeekName ( o ) | String | Get the day of the week name, 1 = Sunday, 7 = Saturday | |
formatDate ( o ) | String | Outputs the date part only (not time) | |
formatDate ( o, timezone ) | String | Get a date only representation of the given date like object, using the given timezone | |
formatTime ( o, timezone ) | String | Output the time in short format for the give timezone | |
formatTimeLong ( o, timezone ) | String | Output the time in long format for the give timezone | |
formatDateLong ( o ) | String | Outputs the date and time in a long format | |
formatDateLong ( o, timezone ) | String | Get a long date and time representation of the given value, using the given timezone | |
formatDateTime ( o ) | String | Outputs date and time short in a compact format | |
getFirstOfMonth ( month, timeZone ) | Date | Outputs a date object with the first day of the specified month in the current year | |
newDate ( year, month, day ) | Date | ||
calcNextBirthday ( date ) | Date | Given a user's birthdate, calculate their next birthday | |
formatDateTime ( o, timezone ) | String | ||
formatDateISO8601 ( o ) | String | Output an ISO8601 representation of the given date like value, for the timezone of the servers This is useful for using with timeago | |
formatDateISO8601 ( o, timezone ) | String | Output an ISO8601 representation of the given date like value, for the given timezone This is useful for using with timeago | |
formatAge ( o ) | String | Returns a user friendly description of the age of the date. Eg "4 minutes ago" | |
formatMinsAsDuration ( o ) | String | For a given value which is some number of minutes, generate a user friendly representation as a duration, eg "1 hour" | |
formatMinsAsDuration ( o, numeric ) | String | Given a value which can be parsed to a Long, return it formatted as a human readable duration such as 12:30 (12 mins, 30 seconds) or 12 mins, 3 hrs 20 | |
pad2 ( l ) | String | ||
pad ( l, length ) | String | ||
getDateTime ( o ) | DateTime | Returns a DateTime, not adjusted for any timezone | |
getDateTime ( o, timezoneId ) | DateTime | Returns a Jodatime DateTime object that can be easily manipulated | |
toPercent ( num, div ) | String | Format as a percentage, including a percentage symbol and where blank/null values result in a blank output | |
toPercent ( num, div, appendSymbol, withBlanks ) | String | ||
format ( o ) | String | Format as a date, if its a date. Otherwise as a string | |
stripExt ( s ) | String | Removes the file extension if present Eg file1.swf -> file1 file1 -> file1 | |
fileExt ( fileName ) | String | Returns the file extension, if there is one. | |
gt ( val1, val2 ) | boolean | True if val1 is greater then val2 will do string conversions | |
lt ( val1, val2 ) | boolean | ||
eq ( val1, val2 ) | boolean | ||
htmlEncode ( s ) | String | Makes the given string suitable for rendering in HTML. Symbols like angle brackets will be encoded so they can be displayed | |
htmlAttEncode ( s2 ) | String | Modifies the given value so that it is suitable for use in HTML attributes This is a lossy conversion, in that multiple unencoded strings might encode to the same att value '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" So, you can't have: the same character that opens/closes the attribute value (either ' or ") a naked ampersand (& must be &) a left angle bracket (< must be <) | |
htmlAttDecode ( s2 ) | String | Just reverses htmlAttEncode, which encodes specific characters not legal for html attributes | |
percentDecode ( s ) | String | Decode percentage encoded paths. Eg a%20b -> a b | |
percentEncode ( s ) | String | ||
between ( oVal, oStart, oFinish ) | boolean | Returns true if the given value is between the start and finish dates, or the respective values are null. Ie if start date is null and finish date is given it will only check that the value is less then the finish date Values are converted using the joda time converters | |
toDate ( oVal ) | Date | ||
toSqlDate ( oVal ) | Date | ||
toJodaDate ( oVal ) | DateTime | ||
toPlain ( html ) | String | For a given piece of HTML, remove HTML tags (fairly crude) | |
getNow ( ) | Date | Get the current date and time | |
yearStart ( dt ) | Date | Returns the date of the first day of the year of the given date | |
monthStart ( dt, month ) | Date | Get the date/time of the first instant of the given month in the year indicated by the given date. The month is zero indexed, ie 0=January This is for the timezone set on the current organisation if there is one | |
monthStart ( dt ) | Date | Return the datetime of the start of thee month of the given date | |
yearEnd ( ) | Date | Get the date/time of the last instant of the current year. | |
yearEnd ( dt ) | Date | Get the date/time of the last instant of the given year indicated by the given date. | |
monthEnd ( dt, month ) | Date | Get the date/time of the last instant of the given month in the year indicated by the given date. The month is zero indexed, ie 0=January This is for the timezone set on the current organisation if there is one | |
durationSecs ( start, finish ) | long | Get the duration from the start to the finish date in seconds. | |
durationHours ( start, finish ) | long | Get the duration from the start to the finish date in seconds. | |
durationMins ( start, finish ) | long | ||
durationDays ( start, finish ) | long | ||
getMonthName ( i ) | String | Returns the long month name (eg January) for the given zero-indexed month, where 0 is January | |
getCurrentDateService ( ) | CurrentDateService | ||
ifEqual ( ifEqual, ifNotEqual, o1, o2 ) | String | If o1 is equal to o2, then output the ifEqual parameter, otherwise the ifNoteEqual parameter This is a nullsafe comparison | |
ifNull ( val, defaultVal ) | Object | Convenience method for when you want a value or some default if the value is null. If the first param is null, or if it is an empty string, then return the second param | |
ifTrue ( bb, o1, o2 ) | Object |
This just permits simple templating syntax for basic conditional values
Eg: |
|
newList ( ) | ResourceList | Just create a new list that you can add to | |
getList ( ) | ResourceList | Just create a new list, same as newList() | |
parseDate ( s ) | Date | ||
sdf ( hasTime ) | DateFormat | ||
toBigDecimal ( o, decimals ) | BigDecimal | ||
calc ( list ) | Calc | Create a new calculator, which can do heaps of cool stuff | |
where ( mvelExpr, list ) | ResourceList | Filter a list with a MVEL expression | |
checkbox ( name, oChecked ) | String | ||
checkbox ( id, name, oChecked ) | String | ||
checkbox ( oId, name, oChecked, oValue ) | String | ||
bsswitch ( oId, name, oChecked, oValue ) | String | Normal checkbox, but optimised for bootstrap switch | |
radioEq ( id, name, currentValue, value ) | String | Generate radio button HTML where you have the currently selected value of the input and the value that this input represents | |
radioEq ( id, name, currentValue, value, className ) | String | Generate radio button HTML where you have the currently selected value of the input and the value that this input represents | |
radio ( id, name, oChecked, value ) | String | Generate a radio button where you have a boolean value which indicates if this radion is currently checked/selected | |
radio ( id, name, oChecked, value, className ) | String | Generate a radio button where you have a boolean value which indicates if this radion is currently checked/selected | |
option ( value, oText, currentValue ) | String | Generate an option element | |
select ( name, data ) | String | Generate a select box with the given options | |
select ( name, currentVal, data ) | String | Generaet a select box with the given options and value | |
select ( id, name, htmlClass, currentVal, data ) | String | Generaet a select box | |
getPort ( ) | int | Attempts to find the port of the current request, defaults to 80 | |
getPortString ( ) | String | Returns empty string if the current request is on port 80, otherwise returns the port number prefixed with a colon, eg :8080 | |
profilePicHref ( p ) | String | ||
toCsv ( list ) | String | ||
toCsv ( list ) | String | ||
toJson ( val ) | String | ||
addDays ( now, days ) | Date | Return a date which has the given number of days added (or subtracted if negative) to the given date | |
addYears ( now, years ) | Date | ||
addDays ( now, days ) | Date | Return a date whic@Doch has the given number of days added (or subtracted if negative) to the given date | |
addMinutes ( now, mins ) | Date | ||
getDomainName ( w ) | String | ||
isNotNull ( o ) | boolean | ||
isNull ( o ) | boolean | ||
getVersionId ( rf ) | String | ||
daysBetween ( from, to ) | List | List the dates between the given dates, including at least the from date | |
endofDay ( dt ) | Date | Return the time of the end of the given day, ie 23:59 Null safe | |
startOfDay ( dt ) | Date | Return the time of the start of the given day, ie 00:00 Null safe | |
truncate ( s, max ) | String | Returns a truncated string with a maximum length of max, followed by 3 fullstops if its truncated | |
newArrayList ( ) | ArrayList | Just creates a new List which you can use in templating for adding objects of any type | |
newMap ( ) | LinkedHashMap | Just creates a new map you can use in templating. Preserves insertion order. | |
newSet ( ) | LinkedHashSet | Just create a new set, which you can use in templating. Preserves insertion order. | |
newMapBuilder ( ) | MapBuilder | Just creates a new map builder you can use in templating. | |
formatBytes ( o ) | String | Convert the given object to a user friendly description of the size, assuming the value is in bytes. If the value is a Resource it will take the content length Eg 300 B, 5 KB, 3 MB | |
formatCurrency ( o ) | String | Use a decimal formatter to format to 2 decimal places, suitable for displaying many currencies | |
formatCurrency ( o, leadingZeros ) | String | Use a decimal formatter to format to 2 decimal places, suitable for displaying many currencies | |
getStartOfWeek ( dt ) | Date | Returns the date of the first day of the week which the given date is in. This considers the first day of the week to be Monday. If you want it to be Sunday just do addDays(-1) | |
sortByProperty ( list, propertyName ) | List | Sort the list by a property name | |
sortReverse ( list ) | List | ||
sort ( list ) | List | Sort a list by its natural comparable | |
toggleParamVal ( paramName, val ) | String | Returns a string which contains all request parameters, but with a particular value toggled, ie added or removed, to the named parameter Toggled parameters are comma seperated lists of values For example, a request to ?categories=A,B&tags=C,D, if you toggleParamVal("tags,"C") that will return categories=A,B&tags=D | |
addNum ( from, addAmount ) | Integer | ||
split ( s, sep ) | String | ||
split ( s ) | String | ||
formatNumeric ( o, format ) | String | Display as a number, including comma seperated. Uses a format pattern like #,###.00 For more options see DecimalFormat WARNING: When using with templating language you need to be VERY CAREFUL about delimiting hashes, because they are templating identifiers | |
formatNumeric ( o ) | String | Uses the default pattern of #,###,###.00 | |
formatNumericNoDecimal ( o ) | String | ||
isNumeric ( o ) | boolean | ||
toBase64String ( o ) | String | Convert an object to an Base64 encoded string | |
fromBase64AsString ( base64 ) | String | ||
fromBase64AsByteArray ( base64 ) | byte | ||
joinByteArray ( b1, b2 ) | byte | ||
copyFromArray ( arr, from, to ) | byte | ||
copyFromArray ( arr, from, to ) | char | ||
getCrypto ( ) | CryptoImpl | Get an instance of the CryptoImpl class | |
getGeoIPService ( ) | GeoIPService | Get an instance of the GeoIPService class | |
parseHtml ( html ) | Jerry | Parses HTML and returns a Document object. This uses the Jerry API which is very similar to JQuery - http://jodd.org/doc/jerry/ | |
formatJodaDate ( date, pattern ) | String | Converts the given date object to a Joda DateTime, and then formats it with the supplied Joda pattern Eg "dd/MM/YYYY HH:mm:ss" See http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html | |
formatJodaDate ( date, pattern, timeZone ) | String | Converts the given date object to a Joda DateTime, and then formats it with the supplied Joda pattern Eg "dd/MM/YYYY HH:mm:ss" See http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html | |
formatAsCleanId ( title ) | String | Returns a value suitable for use as an identifier, ie does not contain spaces or special characters. Spaces are converted | |
formatPhoneNumber ( obj, phone ) | String | Formats a phone number in the E164 format using default rules. | |
textFromHtml ( htmlContents ) | String | Remove html tags, returning plain text suitable for display | |
newTextOptionType ( placeholder ) | TextOptionType | Creates a new TextOptionType | |
newListOptionBuilder ( ) | ListOptionTypeBuilder |
Creates a new ListOptionBuilder
Template Example:
|
|
toPlainEmail ( o ) | String | Parse an email address and returns the plain email address. |
|
textToHtml ( text ) | String |
Returns a html representation of the given text. This will transform
newlines into tags |
|
getRandomGuid ( ) | String | Calculate a random UUID | |
formatUnits ( o ) | String | Converts to a number, and then rounds and abbreviates with a metric suffix Eg 3123 is "3k" | |
encodeAsHtmlEntities ( s ) | String | ||
firstNotNull ( strings ) | String | ||
paginator ( ) | Paginator | Create and return a new paginator | |
translate ( sourceType, sourceId, field, langCode ) | String | ||
translate ( sourceType, sourceId, field ) | String | ||
translate ( sourceType, sourceId ) | String | ||
translate ( source, field ) | String |
Ask a question, or offer an answer